#include<iostream>
#include<string>
#include<random>
#include<stack>
#include<queue>
#include<stdio.h>
#pragma warning(disable : 4996)
using namespace std;

struct TreeNode {
public:
    int val;
    TreeNode* left;
    TreeNode* right;
    TreeNode() : val(0), left(nullptr), right(nullptr) {}
    TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
    TreeNode(int x, TreeNode* left, TreeNode* right) : val(x), left(left), right(right) {}
    
};


class Solution {
public:

    void creat_anwser(string& ret,TreeNode*root)
    {
        if (root == nullptr)
        {
            return;
        }
        ret.append(to_string(root->val));
        if (!(root->left == nullptr && root->right == nullptr))
        {
            ret.push_back('(');
            creat_anwser(ret, root->left);
            ret.push_back(')');
        }
        if (root->right != nullptr)
        {
            ret.push_back('(');
            creat_anwser(ret, root->right);
            ret.push_back(')');
        }
        
    }
    string tree2str(TreeNode* root) {
        string ret;
       creat_anwser(ret, root);
       return ret;

    }
public:
    vector<vector<int>> levelOrder(TreeNode* root) {
        queue<TreeNode*> container;
        vector<vector<int>> ret;
        if (root == nullptr)
        {
            return ret;
        }
        int i = 1;
        int count = 0;
        vector<int> temp;
        container.push(root);
        while (i)
        {
            while (i--)
            {
                temp.push_back(container.front()->val);
                if (container.front()->left != nullptr)
                {
                    container.push(container.front()->left);
                    count++;
                }
                if (container.front()->right != nullptr)
                {
                    container.push(container.front()->right);
                    count++;
                }
                container.pop();
            }
            ret.push_back(temp);
            temp.clear();
            i = count;
            count = 0;
        }
        return ret;



    }

public:
    bool find(TreeNode* root, int p,int q)
    {
        if (root == nullptr)
        {
            return false;
        }
        if (root->val == p || root->val == q)
        {
            return true;
        }
        return find(root->left, p, q) || find(root->right, p, q);
    }


    TreeNode* lowestCommonAncestor(TreeNode* root, TreeNode* p, TreeNode* q) {
        if (find(root, q->val, p->val))
        {
            return root;
        }
        bool left = find(root->left, p->val, q->val);
        bool right = find(root->right, p->val, q->val);
        if (left && right)
        {
            return root;
        }
        else
        {
            if (left)
            {
                return lowestCommonAncestor(root->left, p, q);
            }
            else
            {
                return lowestCommonAncestor(root->right, p, q);
            }
        }

    }

    bool idea_find(TreeNode* root, int value)
    {
        if (root == nullptr)
        {
            return false;
        }
        if (root->val = value)
        {
            return true;
        }
        return idea_find(root->left, value) || idea_find(root->right, value);
    }

    TreeNode* idea(TreeNode* root, TreeNode* p, TreeNode* q)
    {
        if (idea_find(p, q->val))
        {
            return p;
        }
        if (idea_find(q, p->val))
        {
            return q;
        }
        TreeNode* ret=nullptr;
        idea_test(root, p->val, q->val, ret);
        return ret;


    }

    bool idea_test(TreeNode* root,int p,int q,TreeNode* ret)
    {
        if (root == nullptr)
        {
            return false;
        }
        if (root->val == p || root->val == q)
        {
            return true;
        }
        if(idea_test(root->left,p,q,ret)&&idea_test(root->right,p,q,ret))
        {
            ret = root;
            return true;
        }
    }
};

int creat_rand(int a, int b)
{
    srand(time(0));
    return (rand() % (b - a)) + a;


}

void add(TreeNode* root, int value)
{
    if (root->val == 0)
    {
        root->val = value;
        return;
    }
    
    if (root->left == nullptr)
    {
        root->left = new TreeNode(value);
        return;

    }
    else if (root->right == nullptr)
    {
        root->right = new TreeNode(value);
        return;
    }
    int select=creat_rand(1, 3);
    if (select == 1)
    {
        return add(root->left, value);
    }
    else
    {
        return add(root->right, value);
    }
}

void add(int* a)
{
    if (*a < 10)
    {
        *a=*a+1;
        add(a);

    }
    return;
}


int main()
{
    int a = 1;
    add(&a);
    printf("%d", a);
}